﻿using Resto.CostControl.Core.Query.MaterialModule.QueryObject;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Resto.CostControl.Core.Query.MaterialModule.ViewObject;
using Enterprise.Framework.DomainModel.Specifications;
using Enterprise.Framework.DomainModel;
using Resto.CostControl.Core.Facade.MaterialModule.FacadeObject;
using Enterprise.Framework.Core.Container;
using Resto.CostControl.Core.Facade.MaterialModule.DataTransferObject;
using Resto.CostControl.Core.Enums;

namespace Resto.CostControl.UnitTest.MaterialModule
{
    
    
    /// <summary>
    ///这是 MaterialQOTest 的测试类，旨在
    ///包含所有 MaterialQOTest 单元测试
    ///</summary>
    [TestClass()]
    public class MaterialQOTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///QueryMaterialVOByPager 的测试
        ///</summary>
        [TestMethod()]
        public void QueryMaterialVOByPagerTest()
        {
            MaterialFO target = ObjectCreator.Create<MaterialFO>();
            for (int i=1;i<=20;i++)
            {
                MaterialDTO materialDTO = new MaterialDTO()
                {
                    Code = "AAA" + i.ToString(),
                    Name = "AAA" + i.ToString(),
                    ActualSorage = 100m,
                    CurrentPrice = 1.10m,
                    SafeStorage = 200m,
                    Unit = "ss",
                };

                if (i % 2 == 0)
                {
                    materialDTO.Type = MaterialType.SemiMaterial;
                    materialDTO.RawMaterialId = i - 1;
                }
                else
                    materialDTO.Type = MaterialType.RawMaterial;

                target.AddMaterial(materialDTO);
            }

            MaterialQO qo = ObjectCreator.Create<MaterialQO>();
            ISpecification<MaterialVO> spec = Specification<MaterialVO>.Create(p => p.ID > 0);

            PagerCondition pager = new PagerCondition()
            {
                CurrentPage = 2,
                PageSize = 10,
            };

            string orderKey = "Name";
            bool isAscending = true;;

            MaterialVO[] actual;
            actual = qo.QueryMaterialVOByPager(spec, pager, orderKey, isAscending);
            Assert.AreEqual(10, actual.Length);

        }
    }
}
